<?php

include 'InterfaceService.php';

/**
 * Description of Service
 *
 * @author Kelvin Pereira Alves <kelvinpalves@gmail.com>
 */
class Service implements InterfaceService{
    public function delete($model) {
        $sql = "DELETE FROM model WHERE id = ?";
        $sql = str_replace("model", $model->ORM['table'], $sql);
        $sql = str_replace("id", $model->ORM['id'], $sql);
        echo $sql;
    }

    public function findAll($model) {
        $sql = "SELECT columns FROM model modelAs ORDER BY modelAs.orderby";
        
        $sql = str_replace("modelAs", $model->ORM['modelAs'], $sql);
        $sql = str_replace("model", $model->ORM['table'], $sql);
        $sql = str_replace("orderby", $model->ORM['orderby'], $sql);
        $modelAs = $model->ORM['modelAs'];
        
        $lastKey = (count($model->ORM['columnsDb']) - 1);
        
        foreach ($model->ORM['columnsDb'] as $key => $column) {
            $columns .= $modelAs . '.' . $column . (($lastKey == $key) ? ' ' : ', ');
        }
        
        $sql = str_replace("columns", $columns, $sql);
        echo $sql;
    }

    public function findById() {
        
    }

    public function insert() {
        
    }

    public function update() {
        
    }

}
